package com.mk.cloud.common.util;

import org.osgl.util.S;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class RexpUtils {
    private static final String PHONE_REPX = "^(?:0?1)[3456789]\\d{9}$";

    /**
     * 校验手机号的合法性
     *
     * @param phone
     * @return boolean true:手机号正则验证通过，false 手机号格式不正确或手机号为空
     */
    public static boolean phoneValidate(String phone) {
        if (S.isBlank(phone)) {
            return false;
        }
        Pattern pattern = Pattern.compile(PHONE_REPX);
        Matcher matcher = pattern.matcher(phone);
        if (!matcher.matches()) {
            return false;
        }
        return true;
    }
}
